package be.bonamis.umpire.business.impl;

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import be.bonamis.umpire.domain.Dog;
import be.bonamis.umpire.domain.Person;
import be.bonamis.umpire.domain.PersonDog;
import be.bonamis.umpire.repository.DogRepository;
import be.bonamis.umpire.repository.PersonDogRepository;
import be.bonamis.umpire.repository.PersonRepository;


@Service
public class PersonService {

	@Autowired
	private PersonRepository personRepository;
	@Autowired
	private DogRepository dogRepository;
	@Autowired
	private PersonDogRepository personDogRepository;

	@Transactional
	public void importData() {
		Set<Person> persons = new HashSet<Person>
			(Arrays.asList(new Person("Olivier"), new Person("Guido"), new Person("Florent")));
		//personRepository.save(persons);
		Set<Dog> dogs = new HashSet<Dog>
		(Arrays.asList(new Dog("Riri"), new Dog("Fifi")));
		//dogRepository.save(dogs);
//		Person person = personRepository.findByName("Olivier");
//		Dog dog = dogRepository.findByName("Riri");
		Person person = new Person("Olivier");
		Dog dog = new Dog("Riri");
//		Slice slice02 = sliceRepository.findByAmount(10000);
//		Slice slice03 = sliceRepository.findByAmount(12500);
		PersonDog personDog = new PersonDog();
		personDog.setPerson(person);
		personDog.setDog(dog);
		personDog.setAdoptionDate(new Date());
		personDogRepository.save(personDog);
		
//		List<Repartition> repartitions = new ArrayList<Repartition>();
//		repartitions.add(new Repartition(1, Arrays.asList(new Percentage(1, 100))));
//		repartitions.add(new Repartition(2, Arrays.asList(new Percentage(1, 55), new Percentage(1, 45))));
//		repartitions.add(new Repartition(3, Arrays.asList(
//				new Percentage(1, 100), new Percentage(2, 0), new Percentage(3, 0))));
//		repartitionDao.save(repartitions);
	}
}